package com.example.day03;

public  class Shape {

    // methods

    // 求周长
     double getParameter() {
        //
        return 0;
    }

    // 求面积
     double getArea() {
        //
        return 0;
    }

    // 创建 com.example.day03.Shape 类的三个子类：长方形类，圆形类，三角形类，定义合适的 fields

    // 在三个子类中，重写父类 com.example.day03.Shape 的两个方法，并验证

}

class Rectangle extends Shape {
    double height;
    double width;

    public Rectangle(double height, double width) {
        this.height = height;
        this.width = width;
    }

    @Override
    double getParameter() {
        return (this.height + this.width) * 2;
    }

    @Override
    double getArea() {
        return this.height * this.width;
    }

    public static void main(String[] args) {
        Rectangle r = new Rectangle(6.0, 3.0);
        System.out.println(r.getParameter());
        System.out.println(r.getArea());
    }
}

class Circle extends Shape {
    double radius;

    public Circle(double radius) {
        this.radius = radius;
    }

    @Override
    double getParameter() {
        return 2 * Math.PI * this.radius;
    }

    @Override
    double getArea() {
        return Math.PI * this.radius * this.radius;
    }

    public static void main(String[] args) {
        Circle c = new Circle(8.0);
        System.out.println(c.getParameter());
        System.out.println(c.getArea());
    }
}

class Triangle extends Shape {
    double a;
    double b;
    double c;

    public Triangle(double a, double b, double c) {
        if ((a + b) > c && (b + c) > a && (c + a) > b) {
            this.a = a;
            this.b = b;
            this.c = c;
        } else {
            System.out.println("不能构成三角形");
            System.exit(1);
        }
    }

    @Override
    double getParameter() {
        return a + b + c;
    }

    @Override
    double getArea() {
        double s = (a + b + c) / 2;
        return Math.sqrt(s * (s - a) * (s - b) * (s - c)); // square  root
    }

    public static void main(String[] args) {
        Triangle t = new Triangle(1, 4, 5);
        System.out.println(t.getParameter());
        System.out.println(t.getArea());
    }
}
